# -*- coding: utf-8 -*-
class LoanDelivery < ActiveRecord::Base
  has_many :loan_delivery_details ,:dependent => :destroy  #级联删除子表

  belongs_to :warehouse
  belongs_to :employee
  belongs_to :department
  belongs_to :company
  belongs_to :customer
  belongs_to :loan
  belongs_to :product

  def self.findAllDelivery conditionsStr,conditionsHash,paramsHash
    begin
      find(
        :all,
        :conditions => [conditionsStr,conditionsHash],
        :include => [:loan],
        :offset => paramsHash[:offset],
        :limit => paramsHash[:limit],
        :order => 'loan_deliveries.updated_at DESC'
      )
    rescue Exception => e
      logger.info e
    end
  end

  def self.countAllDelivery conditionsStr,conditionsHash
    begin
      count(
        :all,
        :include => [:loan],
        :conditions => [conditionsStr,conditionsHash]
      )
    rescue Exception => e
      logger.info e
    end
  end
end
